<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页开关灯</title>
    <script src="js/jquery-3.2.1.min.js"></script>
    <style>
        .cls {
            background-color: black;
        }
    </style>
</head>

<body>
    <button id="btn">开关灯</button>
    <script>
        $("#btn").click(function() {
            if ($("body").hasClass("cls")) {
                $("body").removeClass("cls");
            } else {
                $("body").addClass("cls");
            }
        });
    </script>
</body>

</html>